import GPS2
import GPS_MAP
from GPS2 import get_lat_lon
import time

latitude_array=[0,0,0,0]#纬度
longitude_array=[0,0,0,0]#经度

#数据处理，将整数和2小数，2为小数，2位小数，分别赋值到一个数组上去。
def float_to_int(data1, xrray):
  data1 = float(data1)
  xrray[0] = int(data1)
  decimal_part = str(round(data1 % 1, 6)).split('.')[1]
  decimal3_first_two = decimal_part[:2]
  decimal3_second_two = decimal_part[2:4]
  decimal3_last_two = decimal_part[4:]
  xrray[1] = int(decimal3_first_two)
  xrray[2] = int(decimal3_second_two)
  xrray[3] = int(decimal3_last_two)
  return xrray

def GPS_datasend():
  global latitude_array
  global longitude_array
  combine=[0,0,0,0,0,0,0,0]
  while True:
    try:
      lat_lon_1 = get_lat_lon()

      # 验证get_lat_lon返回值至少有4个元素
      if len(lat_lon_1) >= 4:
        break
      else:
        print("get_lat_lon返回值元素个数不足4个，正在重新获取...")
    except Exception as e:
      print(f"send data erro: {e}")

  if lat_lon_1 is not None:
    data1 = lat_lon_1[0]  # 假如这个是纬度
    data2 = lat_lon_1[1]
    data3 = lat_lon_1[2]  # 这个是经度
    data4 = lat_lon_1[3]

    latitude_brray = float_to_int(data1, latitude_array)
    longitude_brray = float_to_int(data3, longitude_array)
    # 得到了两个类似数组 12.314213->[12,31,42,13]
    combine = latitude_brray + longitude_brray
    print(combine)

  return combine
